//
// Copyright (C) 2005 Jason Lewis
//

package net.obxlabs.tweetpad.behaviour;

import net.nexttext.Locatable;
import net.nexttext.TextObject;
import net.nexttext.Vector3;
import net.nexttext.Vector3ArithmeticException;
import net.nexttext.behaviour.AbstractAction;
import net.nexttext.behaviour.TargetingAction;
import net.nexttext.behaviour.physics.*;
import net.nexttext.property.NumberProperty;
import net.nexttext.property.Vector3Property;

/**
 * Move an object over the location.
 * 
 * $Id:MoveOver.java 16 2007-11-27 10:50:46Z prisonerjohn $
 */
public class MoveOver extends PhysicsAction implements TargetingAction {
    protected Locatable target;

    /**
     * 
     */
    public MoveOver(int x, int y) {
    	this(new Vector3(x, y));
    }
    
    public MoveOver(Locatable target) {
        this.target = target;
    }

    /**
     * Moves the TextObject over the target.
     */
    public ActionResult behave(TextObject to) {
    	// stop all movement
    	((Vector3Property)to.getProperty("Velocity")).set(new Vector3());
    	
        // get the location of the target
    	to.getPosition().set(target.getLocation());
    	return new ActionResult(true, true, false);
    }

    /**
     * Sets a target to approach.
     */
    public void setTarget(Locatable target) {
       	this.target = target;
    }
}
